package blackhouse_servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import blackhouse_server.seeclassServer;

import com.alibaba.fastjson.JSON;

@WebServlet("/seeclass")
public class seeclass extends HttpServlet
{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException
	{
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		String seek = req.getParameter("seek");
		String name = req.getParameter("classname");
		int key = 0;
		PrintWriter print = resp.getWriter();
		seeclassServer ss = new seeclassServer();
		String json = null;
		try
		{
			if (req.getParameter("key") != null)
			{
				if (!req.getParameter("key").trim().equals(""))
				{
					key = Integer.parseInt(req.getParameter("key"));
					boolean isok = ss.delclassinfo(key, name);
					print.write(isok + "");
				}
			} else
			{
				json = JSON.toJSONString(ss.getClassInfo(seek));
				print.write(json);
			}
		} catch (SQLException e)
		{

			e.printStackTrace();
		}

	}
}
